package com.ze.familyday.familyphotoframesquare;

import com.ze.familyday.familyphotoframesquare.R;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo.State;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class WifiStateReceive extends BroadcastReceiver{

	public final static String TAG = "WIFIReceive";
	View mWifiBtn;
	public WifiStateReceive(View btn) {
		// TODO Auto-generated constructor stub
		super();
		mWifiBtn = btn;
	}
	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		//获得网络连接服务   
	    ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);   
	    // State state = connManager.getActiveNetworkInfo().getState();   
	    // 获取WIFI网络连接状态  
	    State state = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();   
	    // 判断是否正在使用WIFI网络   
	    if (State.CONNECTED == state) {
	    	Log.v(TAG, "WIFI网络");
	    	MainActivity.WIFI_STATE = 1;
	    	new Handler().post(new Runnable() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
					mWifiBtn.setBackgroundResource(R.drawable.login_wifi_on);
				}
			});
	    	
	    } else {
	    	Log.v(TAG, "没有WIFi网络");
	    	MainActivity.WIFI_STATE = 0;
	    	new Handler().post(new Runnable() {
				
				@Override
				public void run() {
					// TODO Auto-generated method stub
					mWifiBtn.setBackgroundResource(R.drawable.main_wifi);
				}
			});
	    }
	}

}
